package com.youku.plugins.toolboxV4.view
{
   import flash.display.Sprite;
   import com.youku.baseUI.YoukuTextField;
   import fl.controls.RadioButtonGroup;
   import flash.utils.Dictionary;
   import com.youku.plugins.toolboxV4.ToolboxFont;
   import fl.controls.ButtonLabelPlacement;
   import flash.events.MouseEvent;
   import flash.events.Event;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFieldAutoSize;
   import com.youku.utils.ReportUtil;
   
   public class HeadPanel extends Sprite
   {
      
      public function HeadPanel() {
         super();
         this.init();
      }
      
      private var _title:YoukuTextField;
      
      private var _tbGroup:RadioButtonGroup;
      
      private var _tbDefer:Array;
      
      private var _tbSelectors:Dictionary;
      
      private function init() : void {
         var _loc2_:ToolBoxRadioButton = null;
         this._tbDefer = [];
         this._tbSelectors = new Dictionary();
         this._tbGroup = new RadioButtonGroup("head");
         this._tbDefer.push(
            {
               "type":"allow",
               "name":"允许"
            });
         this._tbDefer.push(
            {
               "type":"notallow",
               "name":"不允许"
            });
         var _loc1_:Number = 0;
         while(_loc1_ < this._tbDefer.length)
         {
            _loc2_ = new ToolBoxRadioButton();
            _loc2_.group = this._tbGroup;
            _loc2_.costomTextFormat = ToolboxFont.FONT_SELECTOR;
            _loc2_.labelPlacement = ButtonLabelPlacement.RIGHT;
            _loc2_.text = this._tbDefer[_loc1_].name;
            _loc2_.label = "";
            _loc2_.fontHoffset = -2;
            _loc2_.value = this._tbDefer[_loc1_].type;
            this._tbSelectors[this._tbDefer[_loc1_].type] = _loc2_;
            _loc2_.addEventListener(MouseEvent.CLICK,this.onSelectorClick);
            _loc1_++;
         }
         this._tbGroup.addEventListener(Event.CHANGE,this.onHeadChange);
         this._title = AssetUtil.getYoukuTextField(false);
         this._title.defaultTextFormat = ToolboxFont.FONT_COMMON;
         this._title.autoSize = TextFieldAutoSize.LEFT;
         this._title.fontHoffset = -2;
         this._title.text = "跳过片头:";
         this.addChild(this._title);
         this.resetOptions();
      }
      
      private function onSelectorClick(param1:MouseEvent) : void {
         var _loc2_:ToolBoxRadioButton = param1.target as ToolBoxRadioButton;
         switch(_loc2_.value as String)
         {
            case "allow":
               ReportUtil.sendUserActionLog(ReportUtil.SETTINGS_PANEL_PLAY_SKIP_HEADTAIL_ALLOW);
               break;
            case "notallow":
               ReportUtil.sendUserActionLog(ReportUtil.SETTINGS_PANEL_PLAY_SKIP_HEADTAIL_NOT_ALLOW);
               break;
         }
      }
      
      private function resetOptions() : void {
         var _loc1_:ToolBoxRadioButton = null;
         for each(_loc1_ in this._tbSelectors)
         {
            if(contains(_loc1_))
            {
               removeChild(_loc1_);
            }
         }
         addChild(this._tbSelectors["allow"]);
         addChild(this._tbSelectors["notallow"]);
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._title.x = 11;
         this._title.y = 4;
         this._tbSelectors["allow"].setWH(44,18);
         this._tbSelectors["allow"].x = this._title.x + this._title.width + 6;
         this._tbSelectors["allow"].y = 0;
         this._tbSelectors["notallow"].setWH(56,18);
         this._tbSelectors["notallow"].x = this._tbSelectors["allow"].x + this._tbSelectors["allow"].width;
         this._tbSelectors["notallow"].y = 0;
      }
      
      private function onHeadChange(param1:Event) : void {
         var _loc2_:ToolBoxRadioButton = null;
         for each(_loc2_ in this._tbSelectors)
         {
            if(_loc2_ == this._tbGroup.selection)
            {
               _loc2_.selected = true;
            }
            else
            {
               _loc2_.selected = false;
            }
         }
      }
      
      public function setJump(param1:Boolean) : void {
         if(param1)
         {
            this._tbSelectors["allow"].selected = true;
         }
         else
         {
            this._tbSelectors["notallow"].selected = true;
         }
      }
      
      public function getIsJump() : Boolean {
         var _loc1_:* = false;
         if((this._tbGroup.selection) && this._tbGroup.selection.value == "allow")
         {
            _loc1_ = true;
         }
         return _loc1_;
      }
   }
}
